package com.sh.demo.qa.controller;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefaults;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.WebRequest;
import com.sh.demo.qa.util.JsonUtil;
import com.sh.demo.qa.util.PageUtil;

@Controller
public class IndexController {

	protected final static Logger logger = LoggerFactory.getLogger(IndexController.class);

//	@Autowired
//	@Qualifier("groupPurchaseAnalyseService")
//	private GroupPurchaseAnalyseService groupPurchaseAnalyseService;

//	@InitBinder
//    public void initBinder(ServletRequestDataBinder binder) {
//        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
//        binder.registerCustomEditor(Date.class, new CustomDateEditor(df, true));
//    }
	
	@RequestMapping(value = "/", method=RequestMethod.GET)
	public String index(){
		return "index";
	}
	
//	@RequestMapping(value = "/search", method=RequestMethod.POST)
//	public String search(
//			HttpServletRequest request,
//			GroupPurchaseInfo info,
//			@RequestParam(value = "page", defaultValue="0") int pageNumber,
//			@RequestParam(value = "page.size", defaultValue="20") int pageSize,
//			Model model) throws Exception {
//		// 使用单个参数
//		String url = request.getRequestURI();
//		logger.debug("---------------" + info.getName());
//		logger.debug("---------------" + pageNumber);
//		logger.debug("---------------" + pageSize);
//		Map params = BeanUtils.describe(info);
//		Pageable pageable = new PageRequest(pageNumber, pageSize);
//		Page<GroupPurchaseInfo> page = groupPurchaseAnalyseService.readByPage(info, pageable);
//		List<GroupPurchaseInfo> pageList = page.getContent();
//		model.addAttribute("pageList", pageList);
//		String pageBar = PageUtil.getPageBar(url, params, page);
//		model.addAttribute("pageBar", pageBar);
//		model.addAttribute("info", info);
//		return "index";
//	}

//	@RequestMapping(value = "/search", method = RequestMethod.GET)
//	public @ResponseBody String pageable(HttpServletRequest request, Pageable pageable) throws Exception {
//		Page<GroupPurchaseInfo> page = groupPurchaseAnalyseService.readByPage(request.getParameterMap(), pageable);
//		List<GroupPurchaseInfo> result = page.getContent();
//		String json = JsonUtil.outputJsonByFilter("", "", result, false);
//		return json;
//	}

}
